package com.qf.mapper.impl;

import com.qf.mapper.AdminMapper;
import com.qf.pojo.Admin;
import com.qf.utils.DBUtils;

import java.sql.SQLException;

public class AdminMapperImpl implements AdminMapper {
    /**
     * 修改管理员信息
     * @param username
     * @param newPassword
     */
    @Override
    public void update(String username, String newPassword) {
        try {
            DBUtils.commonUpdate("update admin set password=? where username=?", newPassword, username);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 根据username获取管理员
     * @param username
     * @param newPassword
     * @return
     */
    @Override
    public Admin getAdmin(String username, String newPassword) {
        try {
            return DBUtils.commonQueryObj(Admin.class, "select * from admin where username=? and password=?", username, newPassword);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
